package com.example.springexcel;

import com.alibaba.excel.annotation.ExcelProperty;
import com.example.springexcel.utils.ExcelFileUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Random;

@AllArgsConstructor
@NoArgsConstructor
@Data
class User {
    // 名称
    @ExcelProperty("名称")
    private String name;
    // 年纪
    @ExcelProperty("年龄")
    private int age;
    // 电话
    @ExcelProperty("电话")
    private String phone;
}


@Slf4j
public class MainTest {
    //随机生成数据
    private static User RandomUser() {
        User user = new User();

        // 生成随机名称
        String[] names = {
                "胡俊", "胡雅", "胡轩", "胡梓", "胡浩", "胡福", "胡睿", "胡妍", "胡泽", "胡晨",
                "胡雅俊", "胡轩意", "胡莫辛", "胡强", "胡明", "胡敏", "胡磊", "胡阳", "胡安", "胡顾安"
        };
        int nameIndex = new Random().nextInt(names.length);
        user.setName(names[nameIndex]);

        // 生成随机年龄
        int age = new Random().nextInt(100) + 1; // 1~100岁
        user.setAge(age);

        // 生成随机电话号码（符合中国手机号格式）
        String[] phonePrefixes = {"3", "4", "5", "7", "8", "9"};
        int prefixIndex = new Random().nextInt(phonePrefixes.length);
        String prefix = "1" + phonePrefixes[prefixIndex];
        String phoneSuffix = String.format("%08d", new Random().nextInt(100000000)); // 8位数字
        user.setPhone(prefix + phoneSuffix);

        return user;

    }

    //Excel 数据添加
    public static void ExcelDataAdd() {
        ArrayList<User> ListUser = new ArrayList<>();

        for (int i = 0; i < 450000; i++) {
            ListUser.add(RandomUser());
        }
        String file = "/home/huyin/代码/java/java-practice/springExcel/src/main/resources/名称.xlsx";
        ExcelFileUtils.createExcel(file, ListUser, "名称填充");
    }

    public static void main(String[] args) {
        ExcelDataAdd();
    }

}

